﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Data;

namespace GenericLibrariesToolKit
{
    /// <summary>
    /// DAO接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface DAO<T>
    {
        /// <summary>
        /// 新增实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>成功：true，失败：false</returns>
        bool Add(T entity);

        /// <summary>
        /// 根据实体标识符删除实体
        /// </summary>
        /// <param name="entityIdValue">实体标识符值</param>
        /// <returns>成功：true，失败：false</returns>
        bool Delete(object entityIdValue);

        /// <summary>
        /// 根据实体标识符删除多个实体
        /// </summary>
        /// <param name="entityIdValues">实体标识符值数组</param>
        /// <returns>影响数据库记录条数</returns>
        long Delete(object[] entityIdValues);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="operateConditions">删除条件集合</param>
        /// <returns>影响数据库记录条数</returns>
        long Delete(WhereCondition[] whereConditions);

        /// <summary>
        /// 删除实体类型对应的所有实体--谨慎使用此方法
        /// </summary>
        /// <returns>影响数据库记录条数</returns>
        long Delete();

        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>成功：true，失败：false</returns>
        bool Update(T entity);

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="entityIdValue">实体标识符值</param>
        /// <returns>实体记录</returns>
        T Find(object entityIdValue);

        /// <summary>
        /// 获取实体集合
        /// </summary>
        /// <param name="entityId">实体标识符</param>
        /// <param name="entityIdValue">实体标识符值</param>
        /// <returns>实体记录List集合</returns>
        List<T> GetEntityList(string entityId, object entityIdValue, string orderCondition);

        /// <summary>
        /// 根据条件获取实体记录List集合
        /// </summary>
        /// <param name="firstResult">记录开始索引，值为-1时表示不使用分页功能</param>
        /// <param name="maxResult">获取最大记录条数，值为-1时表示不使用分页功能</param>
        /// <param name="whereConditions">where条件数组</param>
        /// <param name="orderByDictionary">order by 条件字典</param>
        /// <returns>实体记录QueryResult</returns>
        QueryResult<T> GetScrollData(int firstResult, int maxResult, WhereCondition[] whereConditions, Dictionary<string, string> orderByDictionary);

        QueryResult<T> GetScrollData(int firstResult, int maxResult, Dictionary<string, string> orderByDictionary);

        QueryResult<T> GetScrollData(int firstResult, int maxResult, WhereCondition[] whereConditions);

        QueryResult<T> GetScrollData(int firstResult, int maxResult);

        QueryResult<T> GetScrollData();

        /// <summary>
        /// 根据条件获取实体记录DataSet
        /// </summary>
        /// <param name="firstResult">记录开始索引，值为-1时表示不使用分页功能</param>
        /// <param name="maxResult">获取最大记录条数，值为-1时表示不使用分页功能</param>
        /// <param name="whereConditions">where条件数组</param>
        /// <param name="orderByDictionary">order by 条件字典</param>
        /// <returns>实体记录DataSet</returns>
        DataSet GetDataSet(int firstResult, int maxResult, WhereCondition[] whereConditions, Dictionary<string, string> orderByDictionary);

        DataSet GetDataSet(int firstResult, int maxResult, Dictionary<string, string> orderByDictionary);

        DataSet GetDataSet(int firstResult, int maxResult, WhereCondition[] whereConditions);

        DataSet GetDataSet(int firstResult, int maxResult);

        DataSet GetDataSet();

    }
}
